﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Lyx.Tools
{
    class SpriteKey
    {
        public int ID = 0; // permet de savoir sur quel spritesheet
        int iCurrentImage = 0;
        public int iNbImages = 0;
        int iCurrentFrame = 0;
        public int iFrameRate = 0;
        public bool bLoop = true;
        public SpriteEffects spriteEffects;

        public int iWidth;
        public int iHeight;

        public SpriteKey(int _ID, int _iNbImages, int _iFrameRate, bool _bLoop, int _iWidth, int _iHeight, SpriteEffects _spriteEffects)
        {
            iNbImages = _iNbImages;
            bLoop = _bLoop;
            iFrameRate = _iFrameRate;
            iWidth = _iWidth;
            iHeight = _iHeight;
            ID = _ID;
            spriteEffects = _spriteEffects;
        }

        public SpriteKey(SpriteKey _spriteKey) : this(_spriteKey.ID, _spriteKey.iNbImages, _spriteKey.iFrameRate, _spriteKey.bLoop, _spriteKey.iWidth, _spriteKey.iHeight, _spriteKey.spriteEffects) { }

        public bool Update(GameTime _gameTime)
        {
            iCurrentFrame += _gameTime.ElapsedGameTime.Milliseconds;

            if (iCurrentFrame > iFrameRate)
            {
                iCurrentFrame = 0;

                iCurrentImage++;

                if (iCurrentImage >= iNbImages)
                {
                    if (bLoop == false)
                    {
                        iCurrentImage = iNbImages - 1;
                        return true;
                    }

                    iCurrentImage = 0;
                }
            }

            return false;
        }

        public int GetCurrentImage() { return iCurrentImage; }
    }
}
